//! Redis集群功能模块
//! 
//! 本模块实现了完整的Redis集群功能，包括：
//! - 分布式哈希槽分片 (16384个槽)
//! - 自动故障检测与恢复
//! - 在线数据迁移
//! - 主从复制与自动切换
//! - Gossip协议节点发现
//! - 集群状态一致性保证

pub mod config;
pub mod node;
pub mod slot;
pub mod network;
pub mod coordinator;
pub mod discovery;
pub mod failover;
pub mod state;
pub mod commands;
pub mod migration;
pub mod replication;
pub mod protocol;
pub mod protocol_parser;
pub mod traits;

// 重新导出核心类型
pub use config::ClusterConfig;
pub use node::ClusterNode;
pub use slot::{SlotManager, CLUSTER_SLOTS};
pub use network::ClusterNetworkManager;
pub use coordinator::ClusterCoordinator;
pub use discovery::GossipProtocol;
pub use state::ClusterState;
pub use commands::{ClusterCommandProcessor, RedisClusterCommand};
pub use failover::{ClusterFailureDetector, ClusterFailoverManager, FailoverConfig, FailoverState, VoteRequest, FailoverEvent};
pub use migration::{ClusterDataMigrator, ClusterMigrationTask, MigrationStatus};
pub use replication::{ClusterReplicationManager, ReplicationState, ReplicationConnection};
pub use protocol::{ClusterProtocolProcessor, ClusterProtocolMessage};
pub use protocol_parser::ClusterProtocolParser;

// 导出所有trait接口
pub use traits::*;

// 集群错误类型
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ClusterError {
    #[error("网络错误: {0}")]
    Network(#[from] std::io::Error),
    
    #[error("序列化错误: {0}")]
    Serialization(#[from] bincode::Error),
    
    #[error("配置错误: {0}")]
    Config(String),
    
    #[error("节点未找到: {0}")]
    NodeNotFound(String),
    
    #[error("槽位未分配: {0}")]
    SlotNotAssigned(u16),
    
    #[error("迁移错误: {0}")]
    Migration(String),
    
    #[error("选举失败: {0}")]
    ElectionFailed(String),
    
    #[error("集群状态不一致")]
    InconsistentState,
    
    #[error("超时: {0}")]
    Timeout(String),
}

pub type ClusterResult<T> = Result<T, ClusterError>;